﻿using System;
using System.Linq;
using System.Linq.Expressions;
using OutDbContext;
using User.Api.Helpers;

namespace User.Api.BizExtensions
{
    public static class DinnerExtensions
    {
        public static IQueryable<DinnerOrder> IsStatus(this IQueryable<DinnerOrder> source,
            params OrderStatus[] orderStatuses)
        {
            if (orderStatuses.Length <= 0)
            {
                return source;
            }

            var intOrderStatus = (int)orderStatuses[0];
            Expression<Func<DinnerOrder, bool>> expression = x => x.OrderStatus == intOrderStatus;

            for (int i = 1; i < orderStatuses.Length; i++)
            {
                var intOrderStatus2 = (int)orderStatuses[i];
                var expressionHelper = new ExpressionHelper<DinnerOrder>();
                expression = expressionHelper.BuildQueryOr(expression, x => x.OrderStatus == intOrderStatus2);
            }

            return source.Where(expression);
        }

        public static IQueryable<DinnerBill> IsStatus(this IQueryable<DinnerBill> source,
            params BillStatus[] billStatuses)
        {
            if (billStatuses.Length <= 0)
            {
                return source;
            }

            var intBillStatus = (int)billStatuses[0];
            Expression<Func<DinnerBill, bool>> expression = x => x.BillStatus == intBillStatus;

            for (int i = 1; i < billStatuses.Length; i++)
            {
                var intBillStatus2 = (int)billStatuses[i];
                var expressionHelper = new ExpressionHelper<DinnerBill>();
                expression = expressionHelper.BuildQueryOr(expression, x => x.BillStatus == intBillStatus2);
            }

            return source.Where(expression);
        }

        // 订单状态，0未支付 1落单中 2落单失败 3退款中 
        // 4退款成功 5退款失败 6落单成功 7微信退餐中 
        // 8微信退餐失败 9微信退餐成功 10微信退餐退款中 
        // 11微信退餐退款失败 12微信退餐退款成功
        public enum OrderStatus
        {
            未支付 = 0,
            落单中 = 1,
            落单失败 = 2,
            退款中 = 3,
            退款成功 = 4,
            退款失败 = 5,
            落单成功 = 6,
            微信退餐中 = 7,
            微信退餐失败 = 8,
            微信退餐成功 = 9,
            微信退餐退款中 = 10,
            微信退餐退款失败 = 11,
            微信退餐退款成功 = 12
        }

        // 支付状态:0-未付款,1-已付款,2-退款中,3-已退款，4-退款失败
        public enum PayStatus
        {
            未付款 = 0,
            已付款 = 1,
            退款中 = 2,
            已退款 = 3,
            退款失败 = 4
        }

        // 1支付中2支付失败3支付成功4退款中5退款成功6退款失败
        public enum BillStatus
        {
            支付中 = 1,
            支付失败 = 2,
            支付成功 = 3,
            退款中 = 4,
            退款成功 = 5,
            退款失败 = 6
        }
    }
}